



import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class MeinServlet
 */
@WebServlet(description = "Ja das ist mein Servlet", urlPatterns = { "/MeinServlet" })
public class MeinServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Integer gib = 1;
    private Benutzer a = new Benutzer(); 
    private BenutzerSpeicher meiner = BenutzerSpeicher.gibMirDeinenSpeicher();
  
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MeinServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		
		
		
		
		RequestDispatcher index= request.getRequestDispatcher("index.jsp");
		index.include(request, response);
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 
		
		
		String u = request.getParameter("Name");
		String e = request.getParameter("E-Mail");
		String p = request.getParameter("passwort");
		String s = request.getParameter("strasse");
		String o = request.getParameter("ort");
		String plz = request.getParameter("plz");
		gib = 1;
		//response.getWriter().println()
		
		if (e != null){
		if (e.length() != 0 && u.length() != 0 && p.length() != 0 && s.length() != 0 && o.length() != 0 && plz.length() != 0 )
		{
			a=new Benutzer();
			a.seteMail(e);
			a.setName(u);
			a.setOrt(o);
			a.setPasswort(p);
			a.setPlz(plz);
			a.setStrasse(s);
			
			if (!meiner.gibtsdenBenutzer(a)){
			meiner.speichereBenutzer(a);
			}
			else {
				gib = 0;
			}
		}
		}
		
		
		request.setAttribute("key", u);
		request.setAttribute("keye", e);
		request.setAttribute("keyp", p);
		request.setAttribute("keys", s);
		request.setAttribute("keyo", o);
		request.setAttribute("keyplz", plz);
		request.setAttribute("keygib", gib);
		
		RequestDispatcher index= request.getRequestDispatcher("index.jsp");
		index.include(request, response);
	}

}
